package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Device;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class DeviceListAdapter extends BaseAdapter {
    private List<Device> datas;
    private Context context;

    public DeviceListAdapter(List<Device> datas, Context context) {
        this.context = context;
        this.datas = datas;

    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.item_search_devicelist, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Device device = datas.get(position);
        holder.name.setText(device.getName());
        holder.model.setText(device.getModel());
        holder.manufacturer.setText(device.getManufacturer());
        holder.number.setText(device.getNumber());
        holder.registerDate.setText(device.getCreateTime()+"  "+device.getUserName());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.name)
        HXTextView name;
        @BindView(R.id.number)
        HXTextView number;
        @BindView(R.id.model)
        HXTextView model;
        @BindView(R.id.manufacturer)
        HXTextView manufacturer;
        @BindView(R.id.state)
        ImageView state;
        @BindView(R.id.state_tv)
        HXTextView stateTv;
        @BindView(R.id.register_date)
        HXTextView registerDate;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
